#include <iostream>
#include <string>
#include <memory>
using namespace std;

class Computer
{

public:
    void Setscreen(string screen) { _screen = screen; }

    void Setboard(string board) { _board = board; }
    void Print(){
        cout<<"Computer的主板是： "<<_board<<endl;
        cout<<"Computer的显示器是： "<<_screen<<endl;
        cout<<"Computer的屏幕是： "<<_os<<endl;

    }
    virtual void Setos() = 0;

protected:
    string _screen;
    string _os;
    string _board;
};

class Maccomputer : public Computer
{

public:
    // 每个电脑系统固定
    void Setos() override
    {
        _os = "Mac_os";
    }
};

class Builder
{  
    public:

    virtual void Buildboard(string board) = 0;
    virtual void Buildscreen(string screen) = 0;
    virtual void Buildos() = 0;
    virtual shared_ptr<Computer> Build() = 0;
};

class Macbuilder : public Builder
{
public:
    Macbuilder() : _com(new Maccomputer) {}

     void Buildscreen (string screen)override
    {
        _com->Setscreen(screen);
    }
     void Buildboard (string board)override {
       _com->Setboard(board);
    }

     void Buildos() override 
    {
        _com->Setos();
    }
     shared_ptr<Computer> Build()
    {
        return _com;
    }

private:
    shared_ptr<Computer> _com;
};


class Director{



   public:
  //当组成部件需要顺序的时候就需要这个指挥者
   Director(shared_ptr<Builder> b):_builder(b){}
   shared_ptr<Computer> Construct(string screen,string board){
         
    _builder->Buildscreen(screen);
    _builder->Buildos();
    _builder->Buildboard(board);
      return  _builder->Build();
   }

   private:
   shared_ptr<Builder> _builder;

};


int main(){


    Director d(make_shared<Macbuilder>());
     d.Construct("戴尔","英伟达")->Print();

}